package com.cddeskywebsite.servlet;

import com.cddeskywebsite.bean.NewsBean;
import com.cddeskywebsite.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(urlPatterns = "/news.jsp")
public class NewsServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //todo 获取分页页码参数
        //1.获取新闻信息
        NewsDao newsDao = new NewsDao();
        List<NewsBean> news = newsDao.getList();
        System.out.println("获取到的新闻数量: " + (news != null ? news.size() : "null"));

        //2.传递新闻信息给前端页面
        req.setAttribute("news",news);
        //3.加载显示前端页面
        req.getRequestDispatcher("newsTemp.jsp").forward(req, resp);
    }
}
